import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

let store = new Vuex.Store({
    // 1. state
    state:{
        headerName: '',
        breadTitle: '',
        menuActive: ''
    },

    // // 2. getters
    getters:{
        getHeaderName(state){
            return state.headerName;
        },
        getBreadTitle(state){
            return state.breadTitle;
        },
        getMenuActive(state){
            return state.menuActive;
        }
    },
    // 3. actions
    // 通常跟api接口打交道
    actions:{
        setHeaderName({commit,state}, name){
            commit("setHeaderName", name);
        },
        setBreadTitle({commit,state}, name){
            commit("setBreadTitle", name);
        },
        setMenuActive({commit,state}, name){
            commit("setMenuActive", name);
        }
    },
    // 4. mutations
    mutations:{
        setHeaderName(state, str){
            state.headerName = str;
        },
        setBreadTitle(state, str){
            state.breadTitle = str;
        },
        setMenuActive(state, str){
            state.menuActive = str;
        }
    }
});

export default store;
